'''从data目录中找到所有的yaml文件；使用case_template.txt作为模板，生成测试用例文件；'''
import os

from setting import DATA_PATH, BASE_PATH, CASES_PATH


def create_case_file():
    file_lists=os.listdir(DATA_PATH) #取出data目录下的所有文件
    template_file = os.path.join(BASE_PATH,'case_template.txt')

    for fList in file_lists:
        if fList.endswith('.yaml')or fList.endswith('.yml'):
            #测试用例文件名和yaml文件名
            data_file = fList.replace('.yaml','').replace('.yml','')
            #测试用例方法名
            test_method_name = data_file.lower() #方法名全小写
            #测试用例类名
            test_class_name = test_method_name.capitalize() #首字母大写
            with open (template_file,'r',encoding='utf-8')as f:
                #从模板文件中取出内容
                content = f.read()%{
                    'class_name':test_class_name.replace('_',''),
                    'method_name':test_method_name,
                    'data_file':data_file
                }
            test_case_file = 'test_xiaobai_%s.py'% data_file
            #根据模板生成测试用例文件
            with open(os.path.join(CASES_PATH,test_case_file),'w',encoding='utf-8') as k:
                k.write(content)



create_case_file()